package com.gedi.data.InputFormate.DBInputFormate;

import org.apache.hadoop.mapred.lib.db.DBWritable;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author:RenPu
 * @Date: 2020/1/13 11:41
 * @Version: 1.0
 * @description:
 */
public class OrderWritable implements DBWritable {

    private Integer orderId;
    private  Double totalMoney;
    private Date createTime;
    private Integer userId;

    public OrderWritable(Integer orderId, Double totalMoney, Date createTime, Integer userId) {
        this.orderId = orderId;
        this.totalMoney = totalMoney;
        this.createTime = createTime;
        this.userId = userId;
    }

    public OrderWritable() {
    }

    public Integer getOrderId() {
        return orderId;
    }

    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }

    public Double getTotalMoney() {
        return totalMoney;
    }

    public void setTotalMoney(Double totalMoney) {
        this.totalMoney = totalMoney;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public void write(PreparedStatement preparedStatement) throws SQLException {

        //设置库表字段的下标值与实体的属性进行对应
        preparedStatement.setInt(2,this.orderId);
        preparedStatement.setDouble(3,this.totalMoney);
        preparedStatement.setDate(4,this.createTime);
        preparedStatement.setInt(5,this.userId);



    }

    public void readFields(ResultSet resultSet) throws SQLException {

        //设置与库表字段对应的映射
        this.orderId=resultSet.getInt("order_id");
        this.totalMoney=resultSet.getDouble("total_money");
        this.createTime=resultSet.getDate("create_time");
        this.userId=resultSet.getInt("user_id");
    }
}
